import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class ActionLoader {
	
	private Scanner input;
	String fileName  = "";
	ArrayList<Action> actionList;
	
	public ActionLoader() {
		super();
		
		actionList = new ArrayList<Action>();
	}
	
	public void setFileName(String fileName){
		this.fileName = fileName; 
	}
	
	
	public void openFile() {
		try {
			input = new Scanner( new File( fileName ) );
		}//end try
		catch ( FileNotFoundException fileNotFoundException ){
			System.err.println( "Error opening file");
			System.exit(1);
		}//end catch
	}//end openFile();
	
	public ArrayList<Action> readActionList(){
		Action action = new Action();
		int actionTriggers = 0;
		ActionTrigger trigger = new ActionTrigger();
		try{
			while(input.hasNext() ==  true){
				actionTriggers = input.nextInt();
				for(int i=0;i<actionTriggers;i++){
					trigger.y = input.nextInt(); //row
					trigger.x = input.nextInt(); //col
					trigger.setFacing( input.nextInt() );
					action.addTrigger(trigger);
					trigger = new ActionTrigger();}// end for
			
			action.setName(input.next());
			action.setDescription(input.nextLine());
			actionList.add(action);
			action = new Action();
		}//end while
			
		}//end try
		catch(NoSuchElementException elementException){
			System.err.println("ActionLoader: Wrong Form");
			System.exit(1);
		}
		catch(IllegalStateException stateException){
			System.err.println("ActionLoader: Wront State");
			System.exit(1);
		}
				
		return actionList;
	}//readMap()

	public void closeFile()
	{
		if ( input != null )
				input.close();
		
	}
}


